<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>生成器generator</title>
    <script>
      function* myGenerator() {
        yield "一";
        yield "条";
        yield "大";
        yield "河";
      }
      const gener = myGenerator();
      console.log(gener.next()); //{value: "一", done: false}
      //   for (let tem of myGenerator()) {
      //     console.log(tem);
      //     /*
      //      * 一
      //      * 条
      //      * 大
      //      * 河
      //      */
      //   }

      function* countdown(begin) {
        while (begin > 0) {
          yield begin--;
        }
      }

      for (let tem of countdown(5)) {
        console.log(tem);
        /*
         * 5
         * 4
         * 3
         * 2
         * 1
         */
      }
    </script>
  </head>
  <body></body>
</html>
